from api.base_api import BaseApi
from common.read_json import read_json
import unittest
from parameterized import parameterized
from common.assert_common import assert_common
from common.html_util import html_util

class TestRecharge(unittest.TestCase):
    def setUp(self) -> None:
        self.recharge_api = BaseApi()
        self.recharge_api.reg_login_mode().user_login("15878945622","l123456")
    def tearDown(self) -> None:
        self.recharge_api.session.close()

    @parameterized.expand(read_json('recharge_data','img_verify_code'))
    def test01_get_recharge_verify_code(self,r,exp_status_code):
        response = self.recharge_api.recharge_mode().get_recharge_verify_code(r)
        self.assertEqual(exp_status_code,response.status_code)

    @parameterized.expand(read_json('recharge_data','rechargeapi'))
    def test02_recharge(self,amount,valicode,exp_status_code,exp_status,exp_description):
        self.recharge_api.recharge_mode().get_recharge_verify_code(512345845554)
        response = self.recharge_api.recharge_mode().recharge(amount,valicode)
        assert_common(self,response,exp_status_code,exp_status,exp_description)

    def test03_third_recharge(self):
        self.recharge_api.recharge_mode().get_recharge_verify_code(512345845554)
        re_response = self.recharge_api.recharge_mode().recharge("500000", "8888")
        url = html_util(re_response)[0]
        form_data = html_util(re_response)[1]
        response_3 = self.recharge_api.recharge_mode().third_recharge(url,form_data)
        self.assertEqual(200,response_3.status_code)
        self.assertIn('OK',response_3.text)

